package cn.edu.scau.cmi.lvmingyan.adapter;

import java.net.URL;
import java.util.*;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;


public class MyController_Class implements Initializable{
	@FXML
	private Button button_add;
	@FXML
	private TextField text_id;
	@FXML
	private TextField text_name;
	@FXML
	private TextArea area;
	List<Integer> List_Id=new ArrayList<>();
	List<Student> List_stu=new ArrayList<>();
	@Override
	public void initialize(URL location, ResourceBundle resources) {
	}
	
	public void onClick(ActionEvent event) {
		
		String string = text_id.getText();
		String name = text_name.getText();
		String str="";
		int id=0;
		try {
		    id = Integer.parseInt(string);
		} catch (NumberFormatException e) {
		    e.printStackTrace();
		}
    	/*if(id==null||name==null) {
    		result.setText("fail to add!");
    		return ;
    	}输入为null的判断操作*/
		Student stu=new Student(name,id);
		
		List_Id.add(id);
		List_stu.add(stu);
		AdapterOfClass a=new AdapterOfClass();
		a.sortInt(List_Id);
		a.matchInt(List_Id, List_stu);
		for(int i=0;i<List_stu.size();i++)
			str=str+(i+1)+"  "+List_stu.get(i).id+"  "+List_stu.get(i).name+"\n";
		area.setText(str);
    	
	}

}
